package org.artifact.core.actor;

import cn.hutool.core.lang.Console;
import cn.hutool.core.thread.ThreadUtil;
import co.paralleluniverse.common.util.CheckedCallable;
import co.paralleluniverse.fibers.Fiber;
import co.paralleluniverse.fibers.FiberAsync;
import co.paralleluniverse.fibers.SuspendExecution;

import java.util.concurrent.ExecutorService;

public class ActorDemo {
    public static void main(String[] args) {
        ExecutorService executorService = ThreadUtil.newSingleExecutor();

        new Fiber<Void>(() -> {
            run(new MyRunnable() {
                @Override
                public void run() throws InterruptedException, SuspendExecution {
                    Console.log("11111111111111111");
                    FiberAsync.runBlocking(executorService, new CheckedCallable<Void, RuntimeException>() {
                        @Override
                        public Void call() throws RuntimeException {
                            Console.log("xxxxxxxxxxxxxxxxxxxxxxxxx");
                            return null;
                        }
                    });

//                    ActorHelper.runBlocking(() -> {
//                        Console.log("xxxxxxxxxxxxxxxxxxxxxxxx");
//                        return null;
//                    });
                    Console.log("222222222222222");
                }
            });
        }).start();

    }


    public static void run(MyRunnable runnable) throws InterruptedException, SuspendExecution {
        runnable.run();
    }
}
